package com.blogs.component;

import java.util.ArrayList;

import com.blogs.entity.ChannelFeed;
import com.blogs.tools.DBSharedPreferences;
import com.blogs.tools.FormatTime;
import com.cnblogs.R;
import com.cnblogs.R.color;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class OffDLChannelAdapter extends BaseAdapter {
	private ArrayList<ChannelFeed> channelList;
	private ViewHolder holder;
	private Activity context = null;
	private DBSharedPreferences sp;
	private boolean isDark;
	private boolean[] bechecks;

	public OffDLChannelAdapter(Activity context, ArrayList<ChannelFeed> feedList, boolean[] bechecks) {
		// TODO Auto-generated constructor stub
		this.context = context;
		this.channelList = feedList;
		this.bechecks = bechecks;
		sp = new DBSharedPreferences(context);
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return channelList.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return channelList.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		isDark = sp.GetIsDarkState();
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.off_dl_channel_adapter_template, null);
			holder = new ViewHolder();
			holder.off_dl_channel_text_tv = (TextView) convertView.findViewById(R.id.off_dl_channel_text_tv);
			holder.off_dl_channel_check_iv = (ImageView) convertView.findViewById(R.id.off_dl_channel_check_iv);
			holder.off_dl_time_text_tv = (TextView) convertView.findViewById(R.id.off_dl_time_text_tv);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.off_dl_channel_text_tv.setText(channelList.get(position).channel_text);
		holder.off_dl_time_text_tv.setText(
					sp.GetStrVarValue(channelList.get(position).channel_name).equals("") ? "" : 
					FormatTime.format(sp.GetStrVarValue(channelList.get(position).channel_name))+"  已下载"
				);
		if (channelList.get(position).isBigType) {
			holder.off_dl_channel_text_tv.setTypeface(Typeface.DEFAULT_BOLD, Typeface.BOLD);
			holder.off_dl_channel_text_tv.setPadding(10, 3, 3, 0);
			holder.off_dl_channel_text_tv.setTextColor(Color.parseColor("#00A2B5"));

		} else {
			holder.off_dl_channel_text_tv.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
			holder.off_dl_channel_text_tv.setPadding(30, 3, 3, 0);
			if (isDark) {
				holder.off_dl_channel_text_tv.setTextColor(context.getResources().getColor(color.con_butom_night));
			} else {
				holder.off_dl_channel_text_tv.setTextColor(Color.parseColor("#000000"));
			}
		}
		if (bechecks[position]) {
			holder.off_dl_channel_check_iv.setImageResource(R.drawable.check_true);
		} else {
			holder.off_dl_channel_check_iv.setImageResource(R.drawable.check_false);
		}
		return convertView;
	}

	class ViewHolder {
		TextView off_dl_channel_text_tv;
		ImageView off_dl_channel_check_iv;
		TextView off_dl_time_text_tv;
	}
}
